package bank.local;

import java.io.IOException;

import bank.Account;
import bank.InactiveException;
import bank.OverdrawException;

public class LocalAccount implements Account {
	
	
	//Owner of the account.
	private String owner;

	//Number of the account.
	private String number;

	//Current balance of the account.
	private double balance;

	//if the account is erased set false
	private boolean active = true;
	
	public LocalAccount(String owner, String number) {
		this.owner = owner;
		this.number = number;
		this.balance = 0.0d;
	}

	public String getNumber() throws IOException {
		return number;
	}

	public String getOwner() throws IOException {
		return owner;
	}

	public boolean isActive() throws IOException {
		return active;
	}

	public void deposit(double amount) throws IOException,
			IllegalArgumentException, InactiveException {
		if (!isActive()) {
			throw new InactiveException();
		}
		else if (amount < 0.0d) {
			throw new IllegalArgumentException();
		}

		balance = balance+amount;
	}

	public void withdraw(double amount) throws IOException,
			IllegalArgumentException, OverdrawException, InactiveException {
		if (!isActive()) {
			throw new InactiveException();
		}
		else if (balance < amount || amount < 0.0d) {
			throw new IllegalArgumentException();
		}

		balance = balance - amount;

	}

	public double getBalance() throws IOException {
		return balance;
	}

	public void remove() {
		if (balance == 0.0d) {
			active = false;
		}
	}

}
